package com.inibb.app.converter;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.inibb.app.constant.GenericCodeConstant;
import com.inibb.app.po.Goods;
import com.inibb.app.po.GoodsPicRef;
import com.inibb.app.vo.GoodsVO;




public class GoodsConvertor {
	
	public static List<GoodsVO> toVOs(List<Goods> pos){
		List<GoodsVO> vos = new ArrayList<GoodsVO>();
		for(Goods po:pos){
			vos.add(toVO(po));
		}
		return vos;
	}
	
	public static List<Goods> toPOs(List<GoodsVO> vos){
		List<Goods> pos = new ArrayList<Goods>();
		for(GoodsVO vo:vos){
			pos.add(toPO(vo));
		}
		return pos;
	}
	
	public static GoodsVO toVO(Goods s){
		GoodsVO vo = new GoodsVO();
		vo.setActvInd(s.getActvInd());
		vo.setBrand(s.getBrand());
		vo.setDesp(s.getDesp());
		vo.setDesp2(s.getDesp2());
		vo.setDesp3(s.getDesp3());
		vo.setGoodsId(s.getGoodsId());
		vo.setName(s.getName());
		vo.setName2(s.getName2());
		vo.setName3(s.getName3());
		vo.setGoodsTypeId(s.getGoodsTypeId());
		vo.setPrice(s.getPrice());
		vo.setUnit(s.getUnit());
		vo.setInstore(s.getInstore());
		vo.setGoodsNo(s.getGoodsNo());
		vo.setHot(s.getHot());
		vo.setNewArrival(s.getNewArrival());
		List<GoodsPicRef> goodsPicRefs = s.getGoodsPicRefs();
		vo.setGoodsPicRefs(goodsPicRefs);
		if(CollectionUtils.isNotEmpty(goodsPicRefs)){
			for(GoodsPicRef gpr:goodsPicRefs){
				if(GenericCodeConstant.IND_YES.equals(gpr.getMainInd())){
					vo.setDefaultPic(gpr.getPic());
					break;
				}
			}
		}
		return vo;
	}
	
	public static Goods toPO(GoodsVO vo){
		Goods po = new Goods();
		po.setActvInd(vo.getActvInd());
		po.setBrand(vo.getBrand());
		po.setDesp(vo.getDesp());
		po.setDesp2(vo.getDesp2());
		po.setDesp3(vo.getDesp3());
		po.setGoodsId(vo.getGoodsId());
		po.setName(vo.getName());
		po.setName2(vo.getName2());
		po.setName3(vo.getName3());
		po.setGoodsTypeId(vo.getGoodsTypeId());
		po.setPrice(vo.getPrice());
		po.setUnit(vo.getUnit());
		po.setInstore(vo.getInstore());
		po.setGoodsNo(vo.getGoodsNo());
		po.setHot(vo.getHot());
		po.setNewArrival(vo.getNewArrival());
		po.setGoodsPicRefs(vo.getGoodsPicRefs());
		return po;
	}
}
